﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.ObjectModel;
using Barbar.MapReport.Common.Drawing;
using Barbar.MapReport.Common.Drawing.Commands;
using Barbar.MapReport.Common;
using Barbar.MapReport.DataSource;

namespace Barbar.MapReport.HtmlRender.Operations.Regions {
  [Serializable]
  internal class RegionWithFixColorData {
    private Collection<RegionListWrapper<ColoredRegionList>> m_ListOfRegionList = new Collection<RegionListWrapper<ColoredRegionList>>();
    private int m_StrokeWeight;

    public RegionWithFixColorData(AddRegionsWithFixColorCommand command) {
      m_StrokeWeight = command.StrokeWeight;
      foreach (ColoredRegionList regionList in command.Regions) {
        m_ListOfRegionList.Add(new RegionListWrapper<ColoredRegionList>(regionList));
      }
    }

    public int StrokeWeight {
      get { return m_StrokeWeight; }
    }

    public IEnumerable<ColoredRegionList> GetValidRegionLists(IGeoBound bound, ZoomLevel zoomLevel) {
      foreach (RegionListWrapper<ColoredRegionList> wrapper in m_ListOfRegionList) {
        if (GeoBound.Intersect(bound, wrapper)) {
          ColoredRegionList regionList = new ColoredRegionList();
          regionList.ToolTip = wrapper.RegionList.ToolTip;
          regionList.FillColor = wrapper.RegionList.FillColor;
          regionList.StrokeColor = wrapper.RegionList.StrokeColor;
          foreach (string regionId in wrapper.RegionList.RegionIds) {
            Polygon polygon = DataSourceManager.GetRegionGeometry(regionId, zoomLevel);
            if (GeoBound.Intersect(bound, polygon))
              regionList.RegionIds.Add(regionId);
          }
          yield return regionList;
        }
      }
    }
  }
}
